package com.lemon.smartsafety.ui.adapter.hidden.list;

import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.utils.common.StringUtils;
import com.lemon.safecloud.greendao.HiddenDangerInfo;

import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/1/27.
 */
public class HiddenListItem implements AdapterItem<HiddenDangerInfo> {

    private View     mMainLayout;
    private TextView tvCheckPart;
    private TextView tvCheckTime;
    private TextView tvCheckLevel;
    private TextView tvCheckFund;
    private TextView tvCheckReport;
    private TextView tvCheckReform;
    private TextView tvAttestCount;


    private RecyclerTClickListener<HiddenDangerInfo> mRecyclerItemClickListener;
    private HiddenDangerInfo                         mData;
    private int                                      mPosition;


    public HiddenListItem(RecyclerTClickListener<HiddenDangerInfo> recycleItemClickListener) {
        this.mRecyclerItemClickListener = recycleItemClickListener;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.item_hidden_info_list;
    }

    @Override
    public void bindViews(View root) {
        mMainLayout = root.findViewById(R.id.main_card_view);
        tvCheckPart = (TextView) root.findViewById(R.id.tvCheckPart);
        tvCheckTime = (TextView) root.findViewById(R.id.tvCheckTime);
        tvCheckLevel = (TextView) root.findViewById(R.id.tvCheckLevel);
        tvCheckFund = (TextView) root.findViewById(R.id.tvCheckFund);
        tvCheckReport = (TextView) root.findViewById(R.id.tvCheckReport);
        tvCheckReform = (TextView) root.findViewById(R.id.tvCheckReform);
        tvAttestCount = (TextView) root.findViewById(R.id.tvAttestCount);
    }

    @Override
    public void setViews() {
        mMainLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mRecyclerItemClickListener != null) {
                    mRecyclerItemClickListener.onItemClick(mData, mPosition);
                }
            }
        });
    }

    @Override
    public void handleData(HiddenDangerInfo data, int position) {
        mData = data;
        mPosition = position;
        tvCheckPart.setText(StringUtils.nullValue(data.getCheckPart()));
        /*
        if (BuildConfig.DEBUG) {
            tvCheckPart.setText(position + ">>" + StringUtils.nullValue(data.getHiddenDangerId()+""));
        }else{
            tvCheckPart.setText(StringUtils.nullValue(data.getCheckPart()));
        }
        */


        String checkDate = StringUtils.nullValue(data.getCheckDate());
        tvCheckTime.setText(checkDate);


        if (data.getLevelName().equals("一般隐患")) {
            tvCheckLevel.setText(data.getLevelName());
        } else {
            tvCheckLevel.setText(Html.fromHtml("<font color='#c9394a'>" + data.getLevelName() + "</font>"));
        }
        tvCheckFund.setText("￥" + StringUtils.nullValue(data.getReformFund(),"0.0"));
        tvCheckReport.setText(data.getStatus() == 1 ? Html.fromHtml("<font color='#259b24'>已上报</font>") : Html.fromHtml("<font color='#c9394a'>未上报</font>"));
        tvCheckReform.setText(data.getIsReformfinished() ? Html.fromHtml("<font color='#259b24'>整改完成</font>") : Html.fromHtml("<font color='#c9394a'>未整改</font>"));
        tvAttestCount.setText(data.getAttestCount() + "");

    }

}
